package cn.wolfcode.handler;

import cn.wolfcode.domain.UserLogin;
import cn.wolfcode.redis.UaaRedisKey;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

import java.util.Date;

@Component
@CanalTable("t_user_info")
public class UserLoginHandler implements EntryHandler<UserLogin> {
    @Autowired
    private StringRedisTemplate redisTemplate;

    public void insert(UserLogin userLogin) {
        System.out.println("用户登录表新增了");
        Long phone = userLogin.getPhone();
        // 添加用户表 redis
        redisTemplate.opsForHash().put(UaaRedisKey.USER_HASH.getRealKey(""), phone.toString(), JSON.toJSONString(userLogin));
        redisTemplate.opsForZSet().add(UaaRedisKey.USER_ZSET.getRealKey(""), phone.toString(), new Date().getTime());
    }

    public void update(UserLogin before, UserLogin after) {
        System.out.println("用户登录表更新了");
    }

    public void delete(UserLogin userLogin) {
        System.out.println("用户登录表删除了");
    }

}
